package com.ruoyi.service.impl;

import com.ruoyi.domain.MineLtcdjc;
import com.ruoyi.domain.SysCoalMachine;
import com.ruoyi.enums.BasicInformationEnum;
import com.ruoyi.mapper.MineLtcdjcMapper;
import com.ruoyi.service.MineLtcdjcService;
import com.ruoyi.utils.WeiteTxtFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service

public class MineLtcdjcServiceImpl implements MineLtcdjcService {
@Autowired
private MineLtcdjcMapper mineLtcdjcMapper;
@Autowired
private WeiteTxtFileUtils weiteTxtFileUtils;

    @Override
    public void mineLtcdjcCreateTxt() {
      List<MineLtcdjc> fileBody= mineLtcdjcMapper.mineLtcdjcCreateTxt();
        for (MineLtcdjc mineLtcdjc : fileBody) {
            String sideCoding = mineLtcdjc.getStationCoding();
            if (sideCoding.equals("13028403000102100000")){
                mineLtcdjc.setDetectedTime(LocalDateTime.now());
            }
        }
      txtMethod(fileBody);
    }
//生成文件头文件名
    public void txtMethod(List<MineLtcdjc> fileBody){
        String fileNameDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String fileHeaderDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String fileName = BasicInformationEnum.FILE_BASIC_INFO.getDesc()+ BasicInformationEnum.CATEGORY_FILE_NAME.getDesc()
                + fileNameDate
                + ".txt";
        String fileHeader = BasicInformationEnum.MINE_FILE_HEADER.getDesc() + fileHeaderDate ;
        weiteTxtFileUtils.urlVerifyAndAdd(BasicInformationEnum.FILE_BASIC_INFO.getDesc(), fileName, fileHeader, fileBody);



    }
}
